<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
    String path = request.getContextPath();
%>
<jsp:include page="/web/inc/header"/>


<section>
<div class="wrap">
  <div id="seach">
    <div id="logo"><a href="http://fenlicx.qinglab.cn" title="垃圾分类查询">分类查询</a></div>
    <div class="seach">
      <input type="text" name="seach" class="seach_txt" id="seach">
      <input type="submit" class="seach_bun" name="button" id="button" value="查询分类">
    </div>
  </div>


<article class="article">
  <div class="title">
    <h1>发布文章</h1>
  </div>


  <form class="writeArticle" method="post" action="<%=path%>/web/article/writeOneArticle">
  <div class="publish">
    <dl>
      <dt>选分类</dt>
      <dd>
          <select id="searchType" name="garbageType.id">
                 <option value="">请选择分类</option>
             <c:forEach items="${requestScope.types}" var="t">
                 <option value="${t.id}">${t.title}</option>
             </c:forEach>
          </select>
      </dd>
    </dl>

    <dl>
      <dt>选材质</dt>
      <dd>
        <span>
          <select id="searchTexture" onchange="childrenTexture(this)">
              <option value="">请选择材质</option>
            <c:forEach items="${requestScope.textures}" var="t">
              <option value="${t.id}">${t.title}</option>
            </c:forEach>
          </select>
        </span>

        <span id="childrenTexture">

        </span>
      </dd>

    </dl>



    <dl>
      <dt>标题</dt>
      <dd>
        <input name="title" type="text" id="title">
      </dd>
    </dl>
    <dl>
      <dt>关键词</dt>
      <dd>
        <input  type="text">
      </dd>
    </dl>
    <dl>
      <dt>内容</dt>
      <dd>
        <textarea id="editorOnline" name="content" cols="" rows=""></textarea>
      </dd>
    </dl>
    <div class="submit">
      <input type="button" onclick="checkAndSubmit()"  value="提交">
      <input type="reset"   value="重置">
    </div>
    </div>

    <input type="hidden" name="userinfo.id" value="${sessionScope.userinfo.id}">
    <input type="hidden" name="texture.id" id="chilText" value="">
  </form>


</article>
</div>
</section>
<script src="<%=path%>/static/js/layui/layui.all.js"></script>
<script src="<%=path%>/static/js/jquery-3.3.1.min.js"></script>
<!-- 配置文件 -->
<script type="text/javascript" src="<%=path%>/ueditor/ueditor.config.js"></script>
<!-- 编辑器源码文件 -->
<script type="text/javascript" src="<%=path%>/ueditor/ueditor.all.js"></script>
<!-- 实例化编辑器 -->
<script type="text/javascript">
    var ue = UE.getEditor('editorOnline',{
        toolbars:[
            [
                'bold',//加粗
                'italic',//斜体
                'superscript', //上标
                'subscript', //下标
                'indent', //首行缩进
                'simpleupload', //单图上传
                'link', //超链接
            ]
        ]
    });
    ue.ready(function () {
        ue.setHeight(200);
    })
</script>
<script>
    function childrenTexture(obj) {
        var texture = $(obj).val();
        if(texture==""){
           $("#childrenTexture").html("");
        }
        else{
          $.ajax({
            url:"<%=path%>/web/texture/childrenTextures2",
            data:{texture:texture},
            type:"GET",
            success:function (data) {
              $("#childrenTexture").html(data);
            }
          })
        }
    }

    function checkAndSubmit() {
        var searchTexture = $("#searchTexture").val();//父级材质id
        var searchChildrenTexture = $("#searchChildrenTexture").val();//子级材质id
        if($("#searchType").val()==""){//没选择类型
          layer.msg("请选择垃圾类型",{icon:5});
          return;
        }
        if(searchTexture==""){//没选父级材质
          layer.msg("请选择垃圾材质",{icon:5});
          return;
        }

        if(searchTexture!=""&&searchChildrenTexture==""){//选了父类材质，没选子类材质
          $("#chilText").val(searchTexture);

        }
        if(searchTexture!=""&&searchChildrenTexture!=""){//父类、子类都选择了
          $("#chilText").val(searchChildrenTexture);

        }

        if($("#title").val()==""){//没写标题
          layer.msg("请输入文章标题",{icon:5});
          return;
        }


        if(ue.getContent().trim().length<20){
          layer.msg("文章内容字数过少",{icon:5});
          return;
        }


        $(".writeArticle").submit();

    }
</script>

<jsp:include page="/web/inc/footer"/>
